import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

const routes = [
    {
        path: '/',
        redirect: '/denglu',
    },
    {
        path: '/zhuce',
        component: () =>
            import(/* webpackChunkName: "about" */ '../views/Zhuce.vue'),
    },
    {
        path: '/denglu',
        component: () =>
            import(/* webpackChunkName: "about" */ '../views/Denglu.vue'),
    },
    {
        path: '/password',
        component: () =>
            import(/* webpackChunkName: "about" */ '../views/Password.vue'),
    },
    {
        path: '/mine',
        component: () =>
            import(/* webpackChunkName: "about" */ '../views/Mine.vue'),
    },
];

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes,
});

router.beforeEach((to, from, next) => {
    if (to.path === '/denglu' || to.path === '/zhuce') {
        next();
    } else {
        if (window.sessionStorage.getItem('token')) {
            next();
        } else {
            next('/denglu');
        }
    }
});

export default router;
